#include "infos.h"

int leda = 11;
int ledb = 10;
int ledc = 9;
int ledd = 8;

int onModulePin = 2;        // Le pin qui permet de switch on/off le module gsm
char inchar;               // le char en entree de lecture sur le bus serie

void switchModule(){
  digitalWrite(onModulePin,HIGH);
  delay(2000);
  digitalWrite(onModulePin,LOW);  
  delay(2000);
}

void setup(){

  pinMode(leda, OUTPUT);
  pinMode(ledb, OUTPUT);
  pinMode(ledc, OUTPUT);
  pinMode(ledd, OUTPUT);
  pinMode(onModulePin, OUTPUT);

  Serial.begin(19200);
  pulse();                        // Indicateur visuel sur la board arduino
  switchModule();

  for (int i=0;i<2;i++){            //On attends que le module gsm s'allume...
    delay(5000);                        
  } 

  Serial.print("AT+CPIN=");
  Serial.print(34,BYTE);
  Serial.print(pin_code);
  Serial.println(34,BYTE);
  delay(2000);

  Serial.println("AT+CMGF=1");         // passage en mode texte pour les SMS
  Serial.println("AT+CNMI=2,2,0,0");   // redirection des SMS dans le port serie
  pulse();
  pulse();
}

void loop(){
  if(Serial.available() > 0)
  {
    inchar = Serial.read();
    delay(10);
    if (inchar == '#')
    {
      delay(10);
      inchar = Serial.read();
      if (inchar=='a') //Si on recoit la chaine "#2" (exemple de commande)
      {
        inchar = Serial.read();
        delay(10);
        if (inchar=='0') //Si on recoit la chaine "#2" (exemple de commande)
        {
          delay(10);
          digitalWrite(leda, LOW);
        } 
        else if (inchar=='1') 
          digitalWrite(leda, HIGH);
        inchar = Serial.read();
        delay(10);
        if (inchar=='b') //Si on recoit la chaine "#2" (exemple de commande)
        {

          inchar = Serial.read();
          delay(10);
          if (inchar=='0') //Si on recoit la chaine "#2" (exemple de commande)
          {
            delay(10);
            digitalWrite(ledb, LOW);
          } 
          else if (inchar=='1') 
            digitalWrite(ledb, HIGH);

          inchar = Serial.read();
          delay(10);
          if (inchar=='c') //Si on recoit la chaine "#2" (exemple de commande)
          {

            inchar = Serial.read();
            delay(10);
            if (inchar=='0') //Si on recoit la chaine "#2" (exemple de commande)
            {
              delay(10);
              digitalWrite(ledc, LOW);
            } 
            else if (inchar=='1') 
              digitalWrite(ledc, HIGH);
            inchar = Serial.read();
            delay(10);
            if (inchar=='d') //Si on recoit la chaine "#2" (exemple de commande)
            {

              inchar = Serial.read();
              delay(10);
              if (inchar=='0') //Si on recoit la chaine "#2" (exemple de commande)
              {
                delay(10);
                digitalWrite(ledd, LOW);
              } 
              else if (inchar=='1') 
                digitalWrite(ledd, HIGH);  

            }
          }
        }
      }
    }
  }
}

void pulse(){
  digitalWrite(leda, HIGH);
  digitalWrite(ledb, HIGH);
  digitalWrite(ledc, HIGH);
  digitalWrite(ledd, HIGH);
  delay(500);
  digitalWrite(leda, LOW);
  digitalWrite(ledb, LOW);
  digitalWrite(ledc, LOW);
  digitalWrite(ledd, LOW);
  delay(100);
  digitalWrite(leda, HIGH);
  delay(200);
  digitalWrite(leda, LOW);
  digitalWrite(ledb, HIGH);
  delay(200);
  digitalWrite(ledb, LOW);
  digitalWrite(ledc, HIGH);
  delay(200);
  digitalWrite(ledc, LOW);
  digitalWrite(ledd, HIGH);
  delay(200);
  digitalWrite(ledd, LOW);
}

















